package org.compiere.process;

import java.awt.Color;
import java.io.File;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;

import jxl.CellFormat;
import jxl.Workbook;
import jxl.biff.FontRecord;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.format.VerticalAlignment;
import jxl.write.Formula;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.NumberFormats;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.adempiere.exceptions.AdempiereException;
import org.apache.commons.net.ntp.TimeStamp;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.compiere.apps.ADialog;
import org.compiere.model.MAttachmentEntry;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.jboss.util.propertyeditor.BigDecimalEditor;
import org.joda.time.DateTime;

import com.lowagie.text.Font;

import extend.org.compiere.hrm.ExcelCell;
import extend.org.compiere.utils.Util;

public class FI_Form2 extends SvrProcess {

	/** Current context */
	private Properties m_ctx;
	/**     */
	private ProcessInfo pi;

	// private Timestamp startDate = null;
	// private Timestamp endDate = null;

	private String startDate = null;
	private String endDate = null;
	private String startDateMinusYear = null;
	private String endDateMinusYear = null;
	private String getSQlresult = null;
	private Timestamp tsEndDate = null;
	private Timestamp tsStartDate = null;
	private Timestamp tsStartDateMinusYear = null;
	private Timestamp tsEndDateMinusYear = null;
	private boolean Thousand = false;

	private static CLogger s_log = CLogger.getCLogger(BalanceSheets.class);
	/** */
	private String path = "";

	/**
	 * Prepare - e.g., get Parameters.
	 */
	@Override
	protected void prepare() {
		log.info("");
		m_ctx = Env.getCtx();
		pi = getProcessInfo();
		ProcessInfoParameter[] para = getParameter();
		for (int i = 0; i < para.length; i++) {
			String name = para[i].getParameterName();
			if (para[i].getParameter() == null)
				;
			else if (name.equals("startDate")) 
				tsStartDate = (Timestamp) para[i].getParameter();
			else if (name.equals("endDate")) 
				tsEndDate = (Timestamp) para[i].getParameter();
			else if (name.equals("Thousand")) 
				Thousand = ((String) para[i].getParameter()).equals("Y");
			else
				log.log(Level.SEVERE, "Unknown Parameter: " + name);
		}
		
		Date lEndDate = new Date(tsEndDate.getTime());
		SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
		int year = lEndDate.getYear() + 1900;
		endDate = format.format(lEndDate);

		endDateMinusYear = endDate.substring(0, 6)
				+ String.valueOf(year - 1);
		
		
		lEndDate = new Date(tsStartDate.getTime());
		year = lEndDate.getYear() + 1900;		
		startDate = format.format(lEndDate);
		
		startDateMinusYear = startDate.substring(0, 6) + String.valueOf(year - 1);
		
//		startDate = "01.01." + String.valueOf(year);
//		startDateMinusYear = "01.01." + String.valueOf(year - 1);
//		endDateMinusYear = endDate.substring(0, 6)
//				+ String.valueOf(year - 1);
		// ---------- get Timestamp dates ---------------{
//		Date d = null;
		Date d2 = null;
		Date d3 = null;
		try {
//			d = format.parse(startDate);
			d2 = format.parse(startDateMinusYear);
			d3 = format.parse(endDateMinusYear);			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		d.parse(endDate);
//		tsStartDate = new Timestamp(d.getTime());
		tsStartDateMinusYear = new Timestamp(d2.getTime());
		tsEndDateMinusYear = new Timestamp(d3.getTime());		
		//}		
		path = Util.localFilePath;
		// / here another code)
	}

	@Override
	protected String doIt() throws Exception {
		// Types of cells for
		Label label;
		Number number;
		// There are checks for a specified pattern
		String templateName = "FI_Form2_tmpl.xls";
		//
		MAttachmentEntry entry = Util.getAttachment(pi, m_ctx, templateName);
		if (entry == null)
			throw new AdempiereException(Msg.translate(m_ctx,
					"NotFoundTemplate") + " " + templateName);

		File templateCopy = new File(Util.localFilePath + "FI_Form2.xls");
		File temporaryFile = entry.getFile(Util.localFilePath + templateName);
		Workbook tableBook = null;
		WritableWorkbook copy = null;
		WritableSheet sheet = null;
		try {
			tableBook = Workbook.getWorkbook(temporaryFile);
			copy = Workbook.createWorkbook(templateCopy, tableBook);
			sheet = copy.getSheet(0);
		} catch (Exception e) {
			ADialog.error(999, null, "Error tableBook. " + e.getMessage());
			return "Error tableBook.";
		}

		String org_name;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		StringBuilder sql = new StringBuilder("select name from ad_org where ad_org_id = 1000000");
		try {
			pstmt = DB.prepareStatement(sql.toString(), null);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				org_name = rs.getString(1);
				WritableFont arial10ptBold = new WritableFont(WritableFont.TIMES, 9, WritableFont.NO_BOLD);
				WritableCellFormat captionStyle = new WritableCellFormat(arial10ptBold);
				label = new Label(0, 4, ("Наименование организации: " + org_name), captionStyle);
				sheet.addCell(label);
				
			}
		} catch (SQLException e) {
			s_log.log(Level.SEVERE, "Report: FI_Form2", e);
			getSQlresult = e.getMessage();
		} finally {
			DB.close(rs, pstmt);
			rs = null;
			pstmt = null;
		}
		
		// ExcelCell cellStart = Utils.getCellStart(tableBook,">>");
		// Style for value column
		WritableFont arial10ptBold = new WritableFont(WritableFont.TIMES, 11, WritableFont.NO_BOLD);
		WritableCellFormat valuestyle = null;
		if(Thousand)
			valuestyle = new WritableCellFormat(arial10ptBold,NumberFormats.THOUSANDS_INTEGER);
		else
			valuestyle = new WritableCellFormat(arial10ptBold,NumberFormats.THOUSANDS_FLOAT); 
//		WritableCellFormat valuestyle = new WritableCellFormat();
		valuestyle.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle.setAlignment(Alignment.RIGHT);
		valuestyle.setVerticalAlignment(VerticalAlignment.CENTRE);
		valuestyle.setWrap(true);
		
		WritableFont arial10ptBold2 = new WritableFont(WritableFont.TIMES, 11, WritableFont.BOLD);
		WritableCellFormat valuestyle2 = null;
		if(Thousand)
			valuestyle2 = new WritableCellFormat(arial10ptBold2,NumberFormats.THOUSANDS_INTEGER);
		else
			valuestyle2 = new WritableCellFormat(arial10ptBold2,NumberFormats.THOUSANDS_FLOAT); 
//		WritableCellFormat valuestyle = new WritableCellFormat();
		valuestyle2.setBorder(Border.LEFT, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle2.setBorder(Border.RIGHT, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle2.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle2.setBorder(Border.TOP, BorderLineStyle.THIN, Colour.BLACK);
		valuestyle2.setAlignment(Alignment.RIGHT);
		valuestyle2.setVerticalAlignment(VerticalAlignment.CENTRE);
		valuestyle2.setWrap(true);
		valuestyle2.setBackground(Colour.getInternalColour(44));
		
//		for(int i=1; i<100;i++){
//			WritableCellFormat valuestyle22 = new WritableCellFormat(arial10ptBold2,NumberFormats.THOUSANDS_INTEGER);;
//			valuestyle22.setBackground(Colour.getInternalColour(44));
//			label = new Label(5, i, Integer.valueOf(i).toString(), valuestyle22);
//			sheet.addCell(label);
//		}
		if(!Thousand){
			WritableCellFormat valuestyle3 = new WritableCellFormat();
			label = new Label(2, 7, "", valuestyle3);
			sheet.addCell(label);
			label = new Label(3, 7, "", valuestyle3);
			sheet.addCell(label);
		}
		
		List<line> l = getDatas();
		if (getSQlresult!=null)
			return Msg.translate(m_ctx, "Ошибка запроса.");

		String caption = " за период, заканчивающийся "
				+ endDate.substring(0, 2) + " "
				+ org.utils.DataUtils.getMonthNameRU(new Date(tsEndDate.getTime())).toLowerCase()
				+ " " + endDate.substring(6, 10) + " года.";

		WritableFont arial10ptBold3 = new WritableFont(WritableFont.TIMES, 11, WritableFont.BOLD);
		WritableCellFormat captionStyle = new WritableCellFormat(arial10ptBold3);
		captionStyle.setAlignment(Alignment.CENTRE);
		captionStyle.setVerticalAlignment(VerticalAlignment.CENTRE);
		
		label = new Label(0, 6, caption, captionStyle);
		sheet.addCell(label);


		if(l.size() == 0)
			return Msg.translate(m_ctx, "По заданому параметру нет данных");
		
		line li = l.get(0);
		// output datas ----------------------------------{
		// 100 = 601+602+603
		BigDecimal zero = new BigDecimal(0);
		Formula formula = null;
		
		BigDecimal v100 = new BigDecimal(0);
		v100 = v100.add(li.v601).add(li.v602).add(li.v603);		
		v100 = (Thousand && v100.compareTo(zero) != 0) ? (v100 =  v100.divide(new BigDecimal(1000))) : v100;
		number = new Number(2, 9, v100.doubleValue(), valuestyle);
		sheet.addCell(number);
		
		BigDecimal v100prev = new BigDecimal(0);
		v100prev = v100prev.add(li.v601prev).add(li.v602prev).add(li.v603prev);
		v100prev = (Thousand && v100prev.compareTo(zero) != 0) ? (v100prev =  v100prev.divide(new BigDecimal(1000))) : v100prev;
		number = new Number(3, 9, v100prev.doubleValue(), valuestyle);
		sheet.addCell(number);
		
		//011 = 701
		li.v701 = (Thousand && li.v701.compareTo(zero) != 0) ? (li.v701 =  li.v701.divide(new BigDecimal(1000))) : li.v701;
		number = new Number(2, 10, li.v701.doubleValue(), valuestyle);
		sheet.addCell(number);
		
		li.v701prev = (Thousand && li.v701prev.compareTo(zero) != 0) ? (li.v701prev =  li.v701prev.divide(new BigDecimal(1000))) : li.v701prev;		
		number = new Number(3, 10, li.v701prev.doubleValue(), valuestyle);
		sheet.addCell(number);
		
		//f012
		formula = new Formula(2,11,"SUM(C10:C11)");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);		
		formula = new Formula(3,11,"SUM(D10:D11)");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);		

		
		//013 = 711
		li.v711 = (Thousand && li.v711.compareTo(zero) != 0) ? (li.v711 =  li.v711.divide(new BigDecimal(1000))) : li.v711;		
		number = new Number(2, 12, li.v711.doubleValue(), valuestyle);
		sheet.addCell(number);
		li.v711prev = (Thousand && li.v711prev.compareTo(zero) != 0) ? (li.v711prev =  li.v711prev.divide(new BigDecimal(1000))) : li.v711prev;		
		number = new Number(3, 12, li.v711prev.doubleValue(), valuestyle);
		sheet.addCell(number);		
		
		//014 = 721
		li.v721 = (Thousand && li.v721.compareTo(zero) != 0) ? (li.v721 =  li.v721.divide(new BigDecimal(1000))) : li.v721;		
		number = new Number(2, 13, li.v721.doubleValue(), valuestyle);
		sheet.addCell(number);
		li.v721prev = (Thousand && li.v721prev.compareTo(zero) != 0) ? (li.v721prev =  li.v721prev.divide(new BigDecimal(1000))) : li.v721prev;		
		number = new Number(3, 13, li.v721prev.doubleValue(), valuestyle);
		sheet.addCell(number);
		
		//015 = 741..747
		BigDecimal v015 = new BigDecimal(0);
		v015 = v015.add(li.v741).add(li.v742).add(li.v743).add(li.v744).add(li.v745).add(li.v746).add(li.v747);
		v015 = (Thousand && v015.compareTo(zero) != 0) ? (v015 =  v015.divide(new BigDecimal(1000))) : v015;		
		number = new Number(2, 14, v015.doubleValue(), valuestyle);
		sheet.addCell(number);

		BigDecimal v015prev = new BigDecimal(0);
		v015prev = v015prev.add(li.v741prev).add(li.v742prev).add(li.v743prev).add(li.v744prev).add(li.v745prev).add(li.v746prev).add(li.v747prev);
		v015prev = (Thousand && v015prev.compareTo(zero) != 0) ? (v015prev =  v015prev.divide(new BigDecimal(1000))) : v015prev;
		number = new Number(3, 14, v015prev.doubleValue(), valuestyle);
		sheet.addCell(number);
		
		//016 = 621..628
		BigDecimal v016 = new BigDecimal(0);
		v016 = v016.add(li.v621).add(li.v622).add(li.v623).add(li.v624).add(li.v625).add(li.v626).add(li.v627).add(li.v628);
		v016 = (Thousand && v016.compareTo(zero) != 0) ? (v016 =  v016.divide(new BigDecimal(1000))) : v016;		
		number = new Number(2, 15, v016.doubleValue(), valuestyle);
		sheet.addCell(number);

		BigDecimal v016prev = new BigDecimal(0);
		v016prev = v016prev.add(li.v621prev).add(li.v622prev).add(li.v623prev).add(li.v624prev).add(li.v625prev).add(li.v626prev).add(li.v627prev).add(li.v628prev);
		v016prev = (Thousand && v016prev.compareTo(zero) != 0) ? (v016prev =  v016prev.divide(new BigDecimal(1000))) : v016prev;		
		number = new Number(3, 15, v016prev.doubleValue(), valuestyle);
		sheet.addCell(number);		

		//f020
		formula = new Formula(2,16,"C12-C13-C14-C15+C16");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);				
		formula = new Formula(3,16,"D12-D13-D14-D15+D16");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);				

		
		//021 = 611..616
		BigDecimal v021 = new BigDecimal(0);
		v021 = v021.add(li.v611).add(li.v612).add(li.v613).add(li.v614).add(li.v615).add(li.v616);
		v021 = (Thousand && v021.compareTo(zero) != 0) ? (v021 =  v021.divide(new BigDecimal(1000))) : v021;		
		number = new Number(2, 17, v021.doubleValue(), valuestyle);
		sheet.addCell(number);

		BigDecimal v021prev = new BigDecimal(0);
		v021prev = v016prev.add(li.v611prev).add(li.v612prev).add(li.v613prev).add(li.v614prev).add(li.v615prev).add(li.v616prev);
		v021prev = (Thousand && v021prev.compareTo(zero) != 0) ? (v021prev =  v021prev.divide(new BigDecimal(1000))) : v021prev;
		number = new Number(3, 17, v021prev.doubleValue(), valuestyle);
		sheet.addCell(number);		

		//022 = 731..734
		BigDecimal v022 = new BigDecimal(0);
		v022 = v022.add(li.v731).add(li.v732).add(li.v733).add(li.v734);
		v022 = (Thousand && v022.compareTo(zero) != 0) ? (v022 =  v022.divide(new BigDecimal(1000))) : v022;
		number = new Number(2, 18, v022.doubleValue(), valuestyle);
		sheet.addCell(number);

		BigDecimal v022prev = new BigDecimal(0);
		v022prev = v022prev.add(li.v731prev).add(li.v732prev).add(li.v733prev).add(li.v734prev);
		v022prev = (Thousand && v022prev.compareTo(zero) != 0) ? (v022prev =  v022prev.divide(new BigDecimal(1000))) : v022prev;
		number = new Number(3, 18, v022prev.doubleValue(), valuestyle);
		sheet.addCell(number);		
		
		//023 = 641 642 761 762
		BigDecimal v023 = new BigDecimal(0);
		v023 = v023.add(li.v641).add(li.v642).add(li.v761).add(li.v762);
		v023 = (Thousand && v023.compareTo(zero) != 0) ? (v023 =  v023.divide(new BigDecimal(1000))) : v023;		
		number = new Number(2, 19, v023.doubleValue(), valuestyle);
		sheet.addCell(number);

		BigDecimal v023prev = new BigDecimal(0);
		v023prev = v023prev.add(li.v641prev).add(li.v642prev).add(li.v761prev).add(li.v762prev);
		v023prev = (Thousand && v023prev.compareTo(zero) != 0) ? (v023prev =  v023prev.divide(new BigDecimal(1000))) : v023prev;
		number = new Number(3, 19, v023prev.doubleValue(), valuestyle);
		sheet.addCell(number);	

		//f100
		formula = new Formula(2,22,"SUM(C17:C22)");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);				
		formula = new Formula(3,22,"SUM(D17:D22)");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);				

		
		//100 = 771
		li.v771 = (Thousand && li.v771.compareTo(zero) != 0) ? (li.v771 =  li.v771.divide(new BigDecimal(1000))) : li.v771;
		number = new Number(2, 23, li.v771.doubleValue(), valuestyle);
		sheet.addCell(number);
		li.v771prev = (Thousand && li.v771prev.compareTo(zero) != 0) ? (li.v771prev =  li.v771prev.divide(new BigDecimal(1000))) : li.v771prev;
		number = new Number(3, 23, li.v771prev.doubleValue(), valuestyle);
		sheet.addCell(number);

		//f200
		formula = new Formula(2,24,"C23-C24");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);						
		formula = new Formula(3,24,"D23-D24");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);
		
		//300 = 631 751
		BigDecimal v300 = new BigDecimal(0);
		v300 = v300.add(li.v631).add(li.v751);
		v300 = (Thousand && v300.compareTo(zero) != 0) ? (v300 =  v300.divide(new BigDecimal(1000))) : v300;
		number = new Number(2, 25, v300.doubleValue(), valuestyle);
		sheet.addCell(number);

		BigDecimal v300prev = new BigDecimal(0);
		v300prev = v300prev.add(li.v631prev).add(li.v751prev);
		v300prev = (Thousand && v300prev.compareTo(zero) != 0) ? (v300prev =  v300prev.divide(new BigDecimal(1000))) : v300prev;
		number = new Number(3, 25, v300prev.doubleValue(), valuestyle);
		sheet.addCell(number);		
		//f300
		formula = new Formula(2,26,"C25-C26");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);						
		formula = new Formula(3,26,"D25-D26");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);		
		
		//f400
		formula = new Formula(2,29,"SUM(C32:C42)");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);				
		formula = new Formula(3,29,"SUM(D32:D42)");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);		
		//f500
		formula = new Formula(2,42,"C30+C27");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);				
		formula = new Formula(3,42,"D30+D27");
		formula.setCellFormat(valuestyle2);
		sheet.addCell(formula);						
		//output datas -----------------------------------------}
		copy.write();
		copy.close();
		tableBook.close();
		temporaryFile.delete();

		try {
			String fileName = Util.localFilePath + "FI_Form2.xls";
			String command = "excel \"" + fileName + "\"";
			Runtime.getRuntime().exec("cmd /c start " + command);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return Msg.translate(m_ctx, "Success");
	}


	private List<line> getDatas() {
		List<line> list = new ArrayList<line>();
		PreparedStatement pstmt = null;
		ResultSet rs = null;

		StringBuilder sql = getSQl(tsStartDate, tsEndDate, tsStartDateMinusYear,
				tsEndDateMinusYear);

		try {
			pstmt = DB.prepareStatement(sql.toString(), null);

			rs = pstmt.executeQuery();
			while (rs.next()) {
				line l = new line();
				l.v601 = rs.getBigDecimal(1); 	l.v601prev = rs.getBigDecimal(2); 
				l.v602 = rs.getBigDecimal(3);	l.v602prev = rs.getBigDecimal(4);
				l.v603 = rs.getBigDecimal(5);	l.v603prev = rs.getBigDecimal(6);
				l.v701 = rs.getBigDecimal(7);	l.v701prev = rs.getBigDecimal(8);
				l.v711 = rs.getBigDecimal(9);	l.v711prev = rs.getBigDecimal(10);
				l.v721 = rs.getBigDecimal(11);	l.v721prev = rs.getBigDecimal(12);
				
				l.v741 = rs.getBigDecimal(13);	l.v741prev = rs.getBigDecimal(14);
				l.v742 = rs.getBigDecimal(15);	l.v742prev = rs.getBigDecimal(16);
				l.v743 = rs.getBigDecimal(17);	l.v743prev = rs.getBigDecimal(18);
				l.v744 = rs.getBigDecimal(19);	l.v744prev = rs.getBigDecimal(20);
				l.v745 = rs.getBigDecimal(21);	l.v745prev = rs.getBigDecimal(22);
				l.v746 = rs.getBigDecimal(23);	l.v746prev = rs.getBigDecimal(24);
				l.v747 = rs.getBigDecimal(25);	l.v747prev = rs.getBigDecimal(26);				
				
				l.v621 = rs.getBigDecimal(27);	l.v621prev = rs.getBigDecimal(28);
				l.v622 = rs.getBigDecimal(29);	l.v622prev = rs.getBigDecimal(30);
				l.v623 = rs.getBigDecimal(31);	l.v623prev = rs.getBigDecimal(32);
				l.v624 = rs.getBigDecimal(33);	l.v624prev = rs.getBigDecimal(34);
				l.v625 = rs.getBigDecimal(35);	l.v625prev = rs.getBigDecimal(36);
				l.v626 = rs.getBigDecimal(37);	l.v626prev = rs.getBigDecimal(38);
				l.v627 = rs.getBigDecimal(39);	l.v627prev = rs.getBigDecimal(40);
				l.v628 = rs.getBigDecimal(41);	l.v628prev = rs.getBigDecimal(42);
				
				l.v611 = rs.getBigDecimal(43);	l.v611prev = rs.getBigDecimal(44);
				l.v612 = rs.getBigDecimal(45);	l.v612prev = rs.getBigDecimal(46);
				l.v613 = rs.getBigDecimal(47);	l.v613prev = rs.getBigDecimal(48);
				l.v614 = rs.getBigDecimal(49);	l.v614prev = rs.getBigDecimal(50);
				l.v615 = rs.getBigDecimal(51);	l.v615prev = rs.getBigDecimal(52);
				l.v616 = rs.getBigDecimal(53);	l.v616prev = rs.getBigDecimal(54);

				l.v731 = rs.getBigDecimal(55);	l.v731prev = rs.getBigDecimal(56);
				l.v732 = rs.getBigDecimal(57);	l.v732prev = rs.getBigDecimal(58);
				l.v733 = rs.getBigDecimal(59);	l.v733prev = rs.getBigDecimal(60);
				l.v734 = rs.getBigDecimal(61);	l.v734prev = rs.getBigDecimal(62);	

				l.v641 = rs.getBigDecimal(63);	l.v641prev = rs.getBigDecimal(64);
				l.v642 = rs.getBigDecimal(65);	l.v642prev = rs.getBigDecimal(66);
				l.v761 = rs.getBigDecimal(67);	l.v761prev = rs.getBigDecimal(68);
				l.v762 = rs.getBigDecimal(69);	l.v762prev = rs.getBigDecimal(70);
				
				l.v771 = rs.getBigDecimal(71);	l.v771prev = rs.getBigDecimal(72);
				
				l.v631 = rs.getBigDecimal(73);	l.v631prev = rs.getBigDecimal(74);
				l.v751 = rs.getBigDecimal(75);	l.v751prev = rs.getBigDecimal(76);				
				
				list.add(l);
			}
		} catch (SQLException e) {
			s_log.log(Level.SEVERE, "Report: FI_Form2", e);
			getSQlresult = e.getMessage();
		} finally {
			DB.close(rs, pstmt);
			rs = null;
			pstmt = null;
		}
		return list;
	}

	private StringBuilder getSQl(Timestamp tsStartDate, Timestamp tsEndDate,
			Timestamp tsStartDateMinusYear, Timestamp tsEndDateMinusYear) {
		StringBuilder sql = new StringBuilder();

		sql.append(" SELECT \n");
		sql.append("  " + '"' + "601" + '"' + ", " + '"' + "601prev" + '"' + "\n");
		sql.append(" ," + '"' + "602" + '"' + ", " + '"' + "602prev" + '"' + "\n"); 
		sql.append(" ," + '"' + "603" + '"' + ", " + '"' + "603prev" + '"' + "\n");
		sql.append(" ," + '"' + "701" + '"' + ", " + '"' + "701prev" + '"' + "\n");
		sql.append(" ," + '"' + "711" + '"' + ", " + '"' + "711prev" + '"' + "\n");
		sql.append(" ," + '"' + "721" + '"' + ", " + '"' + "721prev" + '"' + "\n");
		
		sql.append(" ," + '"' + "741" + '"' + ", " + '"' + "741prev" + '"' + "\n");		
		sql.append(" ," + '"' + "742" + '"' + ", " + '"' + "742prev" + '"' + "\n");		
		sql.append(" ," + '"' + "743" + '"' + ", " + '"' + "743prev" + '"' + "\n");		
		sql.append(" ," + '"' + "744" + '"' + ", " + '"' + "744prev" + '"' + "\n");		
		sql.append(" ," + '"' + "745" + '"' + ", " + '"' + "745prev" + '"' + "\n");		
		sql.append(" ," + '"' + "746" + '"' + ", " + '"' + "746prev" + '"' + "\n");
		sql.append(" ," + '"' + "747" + '"' + ", " + '"' + "747prev" + '"' + "\n");				

		sql.append(" ," + '"' + "621" + '"' + ", " + '"' + "621prev" + '"' + "\n");		
		sql.append(" ," + '"' + "622" + '"' + ", " + '"' + "622prev" + '"' + "\n");		
		sql.append(" ," + '"' + "623" + '"' + ", " + '"' + "623prev" + '"' + "\n");		
		sql.append(" ," + '"' + "624" + '"' + ", " + '"' + "624prev" + '"' + "\n");		
		sql.append(" ," + '"' + "625" + '"' + ", " + '"' + "625prev" + '"' + "\n");		
		sql.append(" ," + '"' + "626" + '"' + ", " + '"' + "626prev" + '"' + "\n");
		sql.append(" ," + '"' + "627" + '"' + ", " + '"' + "627prev" + '"' + "\n");					
		sql.append(" ," + '"' + "628" + '"' + ", " + '"' + "628prev" + '"' + "\n");		

		sql.append(" ," + '"' + "611" + '"' + ", " + '"' + "611prev" + '"' + "\n");		
		sql.append(" ," + '"' + "612" + '"' + ", " + '"' + "612prev" + '"' + "\n");		
		sql.append(" ," + '"' + "613" + '"' + ", " + '"' + "613prev" + '"' + "\n");		
		sql.append(" ," + '"' + "614" + '"' + ", " + '"' + "614prev" + '"' + "\n");		
		sql.append(" ," + '"' + "615" + '"' + ", " + '"' + "615prev" + '"' + "\n");		
		sql.append(" ," + '"' + "616" + '"' + ", " + '"' + "616prev" + '"' + "\n");		

		sql.append(" ," + '"' + "731" + '"' + ", " + '"' + "731prev" + '"' + "\n");		
		sql.append(" ," + '"' + "732" + '"' + ", " + '"' + "732prev" + '"' + "\n");		
		sql.append(" ," + '"' + "733" + '"' + ", " + '"' + "733prev" + '"' + "\n");		
		sql.append(" ," + '"' + "734" + '"' + ", " + '"' + "734prev" + '"' + "\n");		

		sql.append(" ," + '"' + "641" + '"' + ", " + '"' + "641prev" + '"' + "\n");		
		sql.append(" ," + '"' + "642" + '"' + ", " + '"' + "642prev" + '"' + "\n");		
		sql.append(" ," + '"' + "761" + '"' + ", " + '"' + "761prev" + '"' + "\n");		
		sql.append(" ," + '"' + "762" + '"' + ", " + '"' + "762prev" + '"' + "\n");
		
		sql.append(" ," + '"' + "771" + '"' + ", " + '"' + "771prev" + '"' + "\n");

		sql.append(" ," + '"' + "631" + '"' + ", " + '"' + "751prev" + '"' + "\n");
		sql.append(" ," + '"' + "631" + '"' + ", " + '"' + "751prev" + '"' + "\n");		
		
		sql.append(" from \n");
		sql.append(" ( \n");
		sql.append("  \n");
		sql.append(" 	Select \n");
		// sql.append(" 	-- 010 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr)) is null then 0 else (sum(fa.amtacctcr)) end \n");
		sql.append(" 		from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between " + "'" + tsStartDate + "'"
				+ " \n");
		sql.append(" 		and  " + "'" + tsEndDate + "'" + "  \n");
		sql.append(" 		and ce.value like '601%') " + '"' + "601" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr)) is null then 0 else (sum(fa.amtacctcr)) end \n");
		sql.append(" 		from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between " + "'" + tsStartDateMinusYear
				+ "'" + " and " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '601%') \n");
		sql.append(" 	" + '"' + "601prev" + '"' + ", \n");

		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 		from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '602%') " + '"' + "602" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 		from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '602%') \n");
		sql.append(" 	" + '"' + "602prev" + '"' + ", \n");
		sql.append("  \n");

		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 		from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '603%') " + '"' + "603" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 		from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '603%') \n");
		sql.append(" 	" + '"' + "603prev" + '"' + ", \n");
		sql.append("  \n");
		
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '701%') " + '"' + "701" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '701%') \n");
		sql.append(" 	" + '"' + "701prev" + '"' + ", \n");
		sql.append("  \n");

		// sql.append(" 	-- 013 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '711%') " + '"' + "711" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '711%') \n");
		sql.append(" 	" + '"' + "711prev" + '"' + ", \n");
		sql.append("  \n");
		// sql.append(" 	-- 014 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctdr  )) is null then 0 else (sum(fa.amtacctdr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and   " + "'" + tsEndDate + "'"
				+ "  and ce.value like '721%') " + '"' + "721" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctdr  )) is null then 0 else (sum(fa.amtacctdr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '721%') \n");
		sql.append(" 	" + '"' + "721prev" + '"' + ", \n");
		sql.append("  \n");

		// sql.append(" 	-- 015 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '741%') " + '"' + "741" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '741%') \n");
		sql.append(" 	" + '"' + "741prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '742%') " + '"' + "742" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '742%') \n");
		sql.append(" 	" + '"' + "742prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '743%') " + '"' + "743" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '743%') \n");
		sql.append(" 	" + '"' + "743prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '744%') " + '"' + "744" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '744%') \n");
		sql.append(" 	" + '"' + "744prev" + '"' + ", \n");
		sql.append("  \n");
		
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '745%') " + '"' + "745" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '745%') \n");
		sql.append(" 	" + '"' + "745prev" + '"' + ", \n");
		sql.append("  \n");
		
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '746%') " + '"' + "746" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '746%') \n");
		sql.append(" 	" + '"' + "746prev" + '"' + ", \n");
		sql.append("  \n");		
		
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '747%') " + '"' + "747" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '747%') \n");
		sql.append(" 	" + '"' + "747prev" + '"' + ", \n");
		sql.append("  \n");		
		// sql.append(" 	-- 016 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '621%') " + '"' + "621" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '621%') \n");
		sql.append(" 	" + '"' + "621prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '622%') " + '"' + "622" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '622%') \n");
		sql.append(" 	" + '"' + "622prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '623%') " + '"' + "623" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '623%') \n");
		sql.append(" 	" + '"' + "623prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '624%') " + '"' + "624" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '624%') \n");
		sql.append(" 	" + '"' + "624prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '625%') " + '"' + "625" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '625%') \n");
		sql.append(" 	" + '"' + "625prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '626%') " + '"' + "626" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '626%') \n");
		sql.append(" 	" + '"' + "626prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '627%') " + '"' + "627" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '627%') \n");
		sql.append(" 	" + '"' + "627prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '628%') " + '"' + "628" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '628%') \n");
		sql.append(" 	" + '"' + "628prev" + '"' + ", \n");
		sql.append("  \n");
		// sql.append(" 	-- 021 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '611%') " + '"' + "611" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '611%') \n");
		sql.append(" 	" + '"' + "611prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '612%') " + '"' + "612" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '612%') \n");
		sql.append(" 	" + '"' + "612prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '613%') " + '"' + "613" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '613%') \n");
		sql.append(" 	" + '"' + "613prev" + '"' + ", \n");
		sql.append("  \n");		
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '614%') " + '"' + "614" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '614%') \n");
		sql.append(" 	" + '"' + "614prev" + '"' + ", \n");
		sql.append("  \n");		
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '615%') " + '"' + "615" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '615%') \n");
		sql.append(" 	" + '"' + "615prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '616%') " + '"' + "616" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '616%') \n");
		sql.append(" 	" + '"' + "616prev" + '"' + ", \n");
		sql.append("  \n");

		// sql.append(" 	-- 022 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '731%') " + '"' + "731" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '731%') \n");
		sql.append(" 	" + '"' + "731prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '732%') " + '"' + "732" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '732%') \n");
		sql.append(" 	" + '"' + "732prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '733%') " + '"' + "733" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '733%') \n");
		sql.append(" 	" + '"' + "733prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '734%') " + '"' + "734" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '734%') \n");
		sql.append(" 	" + '"' + "734prev" + '"' + ", \n");
		sql.append("  \n");

		// sql.append(" 	-- 023 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '641%') " + '"' + "641" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '641%') \n");
		sql.append(" 	" + '"' + "641prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '642%') " + '"' + "642" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '642%') \n");
		sql.append(" 	" + '"' + "642prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '761%') " + '"' + "761" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '761%') \n");
		sql.append(" 	" + '"' + "761prev" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between   " + "'" + tsStartDate + "'"
				+ "  and     " + "'" + tsEndDate + "'"
				+ "   and  ce.value like '762%') " + '"' + "762" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '762%') \n");
		sql.append(" 	" + '"' + "762prev" + '"' + ", \n");
		sql.append("  \n");		
		
		// sql.append(" 	-- 101 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctdr  )) is null then 0 else (sum(fa.amtacctdr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '771%') " + '"' + "771" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctdr  )) is null then 0 else (sum(fa.amtacctdr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '771%') \n");
		sql.append(" 	" + '"' + "771prev" + '"' + ", \n");
		sql.append("  \n");

		// sql.append(" 	-- 300 -------------------------------------------------------------------------------------------------------- \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '631%') " + '"' + "631" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '631%') \n");
		sql.append(" 	" + '"' + "631prev" + '"' + ", \n");
		sql.append("  \n");		
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and  fa.dateacct between " + "'" + tsStartDate + "'"
				+ " and  " + "'" + tsEndDate + "'"
				+ "  and ce.value like '751%') " + '"' + "751" + '"' + ", \n");
		sql.append("  \n");
		sql.append(" 	(select case when (sum(fa.amtacctcr  )) is null then 0 else (sum(fa.amtacctcr  )) end \n");
		sql.append(" 	from fact_acct fa, c_elementvalue ce where fa.account_id = ce.c_elementvalue_id \n");
		sql.append(" 		and fa.dateacct between  " + "'" + tsStartDateMinusYear
				+ "'" + " and  " + "'" + tsEndDateMinusYear + "'" + " \n");
		sql.append(" 		and ce.value like '751%') \n");
		sql.append(" 	" + '"' + "751prev" + '"' + " \n");
		sql.append("  \n");			
		// sql.append(" 	( \n");
		// sql.append(" 		select 	name \n");
		// sql.append(" 			from c_bpartner \n");
		// sql.append(" 		where \n");
		// sql.append(" 			c_bpartner_id = '1000467' limit 1 \n");
		// sql.append(" 		limit 1 \n");
		// // sql.append(" 		/*select cb.name	from hr_job hb \n");
		// //
		// sql.append(" 			inner join hr_employee he on he.hr_job_id = hb.hr_job_id \n");
		// //
		// sql.append(" 			inner join c_bpartner cb on he.c_bpartner_id = cb.c_bpartner_id \n");
		// // sql.append(" 		where hb.hr_job_id = '1000001' \n");
		// // sql.append(" 		limit 1 \n");
		// // sql.append(" 		*/ \n");
		// sql.append(" 	) director \n");
		// sql.append("  \n");
		// sql.append(" 	(	select cb.name	from hr_job hb \n");
		// sql.append(" 			inner join hr_employee he on he.hr_job_id = hb.hr_job_id \n");
		// sql.append(" 			inner join c_bpartner cb on he.c_bpartner_id = cb.c_bpartner_id \n");
		// sql.append(" 		where hb.hr_job_id = '1000010' \n");
		// sql.append(" 		limit 1 \n");
		// sql.append(" 	) chief_accountant, \n");
		// sql.append("  \n");
		// sql.append(" 	(	select cb.name	from hr_job hb \n");
		// sql.append(" 			inner join hr_employee he on he.hr_job_id = hb.hr_job_id \n");
		// sql.append(" 			inner join c_bpartner cb on he.c_bpartner_id = cb.c_bpartner_id \n");
		// sql.append(" 		where hb.hr_job_id = '1000009' \n");
		// sql.append(" 		limit 1 \n");
		// sql.append(" 	) chief_economist \n");
		// sql.append("  \n");
		sql.append(" ) as main \n");
		return sql;
	}
	
	class line {
		BigDecimal v601 = null;		BigDecimal v601prev = null;
		BigDecimal v602 = null;		BigDecimal v602prev = null;
		BigDecimal v603 = null; 	BigDecimal v603prev = null;
		BigDecimal v701 = null; 	BigDecimal v701prev = null;
		BigDecimal v711 = null; 	BigDecimal v711prev = null;
		BigDecimal v721 = null; 	BigDecimal v721prev = null;
		
		BigDecimal v741 = null; 	BigDecimal v741prev = null;
		BigDecimal v742 = null; 	BigDecimal v742prev = null;
		BigDecimal v743 = null; 	BigDecimal v743prev = null;
		BigDecimal v744 = null; 	BigDecimal v744prev = null;
		BigDecimal v745 = null; 	BigDecimal v745prev = null;
		BigDecimal v746 = null; 	BigDecimal v746prev = null;
		BigDecimal v747 = null; 	BigDecimal v747prev = null;
		
		BigDecimal v621 = null; 	BigDecimal v621prev = null;
		BigDecimal v622 = null; 	BigDecimal v622prev = null;
		BigDecimal v623 = null; 	BigDecimal v623prev = null;
		BigDecimal v624 = null; 	BigDecimal v624prev = null;
		BigDecimal v625 = null; 	BigDecimal v625prev = null;
		BigDecimal v626 = null; 	BigDecimal v626prev = null;
		BigDecimal v627 = null; 	BigDecimal v627prev = null;		
		BigDecimal v628 = null; 	BigDecimal v628prev = null;
		
		BigDecimal v611 = null; 	BigDecimal v611prev = null;
		BigDecimal v612 = null; 	BigDecimal v612prev = null;
		BigDecimal v613 = null; 	BigDecimal v613prev = null;
		BigDecimal v614 = null; 	BigDecimal v614prev = null;
		BigDecimal v615 = null; 	BigDecimal v615prev = null;
		BigDecimal v616 = null; 	BigDecimal v616prev = null;
		
		BigDecimal v731 = null; 	BigDecimal v731prev = null;
		BigDecimal v732 = null; 	BigDecimal v732prev = null;
		BigDecimal v733 = null; 	BigDecimal v733prev = null;
		BigDecimal v734 = null; 	BigDecimal v734prev = null;		

		BigDecimal v641 = null; 	BigDecimal v641prev = null;
		BigDecimal v642 = null; 	BigDecimal v642prev = null;
		BigDecimal v761 = null; 	BigDecimal v761prev = null;
		BigDecimal v762 = null; 	BigDecimal v762prev = null;
		
		BigDecimal v771 = null; 	BigDecimal v771prev = null;
		
		BigDecimal v631 = null; 	BigDecimal v631prev = null;	
		BigDecimal v751 = null; 	BigDecimal v751prev = null;			
	}
	
}